﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CoreHelper.Validation.Validators
{
    [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false)]
    public class MinValidatorAttribute : BaseValidatorAttribute
    {
        public MinValidatorAttribute(double number) : this(number, ValidationUtils.Messages.Min)
        {
        }
        public MinValidatorAttribute(double number, string errorMessage) : base(errorMessage)
        {
            Number = number;
        }

        public double Number { get; protected set; }


        public override bool IsValid(object value)
        {
            var val = ValidationUtils.GetValueSize(value);
            if (val == null) return false;
            return val >= Number;
        }

        public override string FormatErrorMessage()
        {
            return string.Format(ErrorMessage, Number);
        }
    }
}
